package com.witmore.skyline.web.task;

import com.witmore.skyline.web.service.CameraCaptureTpService;
import com.witmore.skyline.web.service.CameraCaptureYinShiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Profile({"prod","dev"})
@Slf4j
@Service
public class DeviceCapturePicScheduledTask {

    @Autowired
    private CameraCaptureTpService cameraCaptureTpService;
    @Autowired
    private CameraCaptureYinShiService cameraCaptureYinShiService;

    /**
     * 每20分钟 TP-Link 摄像头执行抓拍任务 向 TP-Link 摄像头创建抓图任务
     */
    @Scheduled(cron = "0 0/20 * * * ?")
    public void executeCapturePicTaskTP() {
        log.info("TP-Link 开始执行抓拍任务");
        try {
            cameraCaptureTpService.executeSubmitCapturePicTaskTP(null);
            log.info("TP-Link 结束执行抓拍任务");
        } catch (Exception e) {
            log.error("TP-Link 本地执行抓拍任务失败 error msg :", e);
        }

    }

    /**
     * 每21分钟 萤石 摄像头执行抓拍任务
     */
    @Scheduled(cron = "0 21 * * * ?")
    public void executeCapturePicTaskYS() {
        log.info("萤石 开始执行抓拍任务");
        try {
            cameraCaptureYinShiService.executeSubmitCapturePicTaskYS(null);
            log.info("萤石 结束执行抓拍任务");
        } catch (Exception e) {
            log.error("萤石 本地执行抓拍任务失败 error msg :", e);
        }

    }
}
